package com.qingyun.edusysteam.controller;

import com.qingyun.edusysteam.dto.FeedbackDTO;
import com.qingyun.edusysteam.dto.Result;
import com.qingyun.edusysteam.service.IFeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 课堂反馈 前端控制器
 * </p>
 *
 * @author your_name
 * @since 2025-08-23
 */
@Slf4j
@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    
    @Autowired
    private IFeedbackService feedbackService;
    
    @GetMapping("/listByStudent")
    public Result listByStudent(@RequestParam("studentId") Long studentId,
                               @RequestHeader("Authorization") String token){
        return feedbackService.listByStudent(studentId, token);
    }

    @PostMapping
    public Result postFeedback(@RequestBody FeedbackDTO feedbackDTO,
                              @RequestHeader("Authorization") String token){
        return feedbackService.postFeedback(feedbackDTO);
    }

    /**
     * 上传单张反馈图片
     * @param file 图片文件
     * @param token 用户token
     * @return 上传结果
     */
    @PostMapping("/photo/upload")
    public Result uploadPhoto(@RequestParam("file") MultipartFile file,
                             @RequestHeader("Authorization") String token) {
        log.info("收到单张图片上传请求，文件名: {}", file.getOriginalFilename());
        return feedbackService.uploadFeedbackPhoto(file, token);
    }
    
    /**
     * 批量上传反馈图片
     * @param files 图片文件数组
     * @param token 用户token
     * @return 上传结果
     */
    @PostMapping("/photos/upload")
    public Result uploadPhotos(@RequestParam("files") MultipartFile[] files,
                              @RequestHeader("Authorization") String token) {
        log.info("收到批量图片上传请求，文件数量: {}", files.length);
        return feedbackService.uploadFeedbackPhotos(files, token);
    }
}
